/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modules.pathloss.model;

import datatypes.Antenna;
import tools.settings.Settings;
import tools.settings.SettingsMissingException;

/**
 *
 * @author jonasverstuyft
 */
public class Erceg implements PathLossModel{

    private String[] snames = {"coverage_requirement", "urban_correction",
        "indoor", "ms_height"};
    
    public double[] getLogDistance(Settings settings, Antenna a) throws SettingsMissingException {
        
        double f = a.getFrequency();
        float p = Float.parseFloat(settings.getSettingsValue("coverage_requirement")) / 100;
        double hb = a.getHeight();
        if(hb == 0)
            hb = 1;
        double hm = Double.parseDouble(settings.getSettingsValue("ms_height"));

        double p_a = 3.6;
        double p_b = 0.005;
        double p_c = 20;
        double delta_h = -20;
        double shadowing = 13;
        double ref_f = 2000;
        double ref_hm = 2;

        
        double[] mapl = new double[2];

        mapl[0] = 20*Math.log10(4*Math.PI*100*f/300) + 6*Math.log10(f/ref_f) + delta_h*Math.log10(hm/ref_hm) + shadowing
                + Calculator.getUrbanCorrection(a, settings);
        mapl[1] = 10*(p_a - p_b*hb + p_c/hb);

        return mapl;

    }

    public double getPathLoss(Settings settings, Antenna a, double distance) throws SettingsMissingException {

        double f = a.getFrequency();
        float p = Float.parseFloat(settings.getSettingsValue("coverage_requirement")) /100;
        double hm = Double.parseDouble(settings.getSettingsValue("ms_height"));
        double hb = a.getHeight();
        if(hb == 0)
            hb = 1;
        double d = distance / 1000; // to km.

        double p_a = 4.6;
        double p_b = 0.0075;
        double p_c = 12.6;
        double delta_h = -10.5;
        double shadowing = 15.6;
        double ref_f = 2000;
        double ref_hm = 2;

        return 20*Math.log10(4*Math.PI*100*f/300) + 6*Math.log10(f/ref_f) + shadowing*Math.log10(hm/ref_hm) + delta_h
                + Calculator.getUrbanCorrection(a, settings) + 10*(p_a - p_b*hb + p_c/hb) * Math.log10(d);
    }

    public String[] getRequiredSettingNames() {
        return snames;
    }

    private double getAntennaHeightCorrectionTerm(double f, double hm) {
        return (1.1 * Math.log10(f) - 0.7) * hm - (1.56 * Math.log10(f) - 0.8);
    }
}
